package com.example.input;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;

import com.example.utils.LengthValidator;
import com.example.utils.HideKeyBordTextWatcher;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 */
public class FullscreenActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);

        TextView displayView = findViewById(R.id.displayView);

        Switch bootOnStartSwitch = findViewById(R.id.BootOnStartSwitch);
        bootOnStartSwitch.setOnCheckedChangeListener((CompoundButton buttonView, boolean isChecked) -> {

            displayView.setText(isChecked ? "选中" : "未选中");
        });


        RadioGroup radioGroup = findViewById(R.id.sexRadioGroup);
        TextView sexLabel = findViewById(R.id.yourSex);
        radioGroup.setOnCheckedChangeListener((RadioGroup group, int checkedId) -> {
            sexLabel.setText("你的性别:" + (checkedId == R.id.male ? "男" : "女"));
        });

        EditText account = findViewById(R.id.account);
        account.setOnFocusChangeListener(new LengthValidator(this, 11, "请输入有效的手机号"));

        EditText password = findViewById(R.id.password);
        password.setOnFocusChangeListener(new LengthValidator(this, 6, "请输入6位长度的密码"));

        // 输入到达指定位数的时候隐藏输入键盘
        account.addTextChangedListener(new HideKeyBordTextWatcher(this,11,account));
        password.addTextChangedListener(new HideKeyBordTextWatcher(this,6,password));


        findViewById(R.id.readMe).setOnClickListener(view->{

            AlertDialog alertDialog = new AlertDialog.Builder(this).setTitle("提示")
                    .setMessage("您确认同意用户协议吗吗？")
                    .setPositiveButton("赞成", (dialog, which) -> {
                        Toast.makeText(this, "谢谢你，好心的大哥哥", Toast.LENGTH_SHORT).show();
                    })
                    .setNegativeButton("绝对不行", (dialog, which) -> {
                        Toast.makeText(this, "真是个悲伤的故事", Toast.LENGTH_SHORT).show();
                    }).create();

            alertDialog.show();
        });


        findViewById(R.id.setBirthday).setOnClickListener(view->{
            DatePickerDialog datePickerDialog = new DatePickerDialog(this, (DatePicker v, int year, int month, int dayOfMonth) -> {
                Toast.makeText(this, String.format("设置了%s年%s月%s日", year, month + 1, dayOfMonth), Toast.LENGTH_SHORT).show();
            }, 2024, 7, 14);


            datePickerDialog.show();
        });

        findViewById(R.id.login).setOnClickListener(view->{


            startActivity(new Intent(this,LoginActivity.class));
        });
    }


}